<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>FEUP-Defender: Timer-Counter</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Gerado por Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="../../main.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="../../modules.html"><span>Módulos</span></a></li>
      <li><a href="../../annotated.html"><span>Estruturas&nbsp;de&nbsp;dados</span></a></li>
      <li><a href="../../files.html"><span>Ficheiros</span></a></li>
      <li><a href="../../dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>Timer-Counter</h1><table border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><h2>Funções</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga6617a30ded5d745873f7de678030d10c">timer_init</a> (int timer, int mode)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gae17f36dbe5d10ebced7a88cc463a7ea9">timer_load</a> (int timer, int value)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga65b0826657eae773861306a352355c7e"></a><!-- doxytag: member="TimerCounter::get_divider" ref="ga65b0826657eae773861306a352355c7e" args="(float freq)" -->
int&nbsp;</td><td class="memItemRight" valign="bottom"><b>get_divider</b> (float freq)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga50796930b8e562f692a38c60a378c5fd"></a><!-- doxytag: member="TimerCounter::clock_sleep" ref="ga50796930b8e562f692a38c60a378c5fd" args="(int clocks)" -->
void&nbsp;</td><td class="memItemRight" valign="bottom"><b>clock_sleep</b> (int clocks)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga41884d7120e9408d1c5719e2858f6564">mili_sleep</a> (int mili)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga0e9d3dc8f167970fe922c56d47d84850">sec_sleep</a> (int secs)</td></tr>
<tr><td colspan="2"><h2>Timer Address</h2></td></tr>
<tr><td colspan="2"><p><a class="anchor" id="amgrp6e55b863430fd8bd7e27be8ff21ed918"></a> </p>
<br/><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gacc9ff9df4a9674a1ce9ba08fc4a4679e"></a><!-- doxytag: member="TimerCounter::TIMER_0" ref="gacc9ff9df4a9674a1ce9ba08fc4a4679e" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gacc9ff9df4a9674a1ce9ba08fc4a4679e">TIMER_0</a>&nbsp;&nbsp;&nbsp;0x40</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Adress of Timer0 divider. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gac62c99c2a9289891c1b83052242cca49"></a><!-- doxytag: member="TimerCounter::TIMER_1" ref="gac62c99c2a9289891c1b83052242cca49" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gac62c99c2a9289891c1b83052242cca49">TIMER_1</a>&nbsp;&nbsp;&nbsp;0x41</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Adress of Timer1 divider. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga1f34f18ad0ab8cace46b615773b48735"></a><!-- doxytag: member="TimerCounter::TIMER_2" ref="ga1f34f18ad0ab8cace46b615773b48735" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga1f34f18ad0ab8cace46b615773b48735">TIMER_2</a>&nbsp;&nbsp;&nbsp;0x42</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Adress of Timer2 divider. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga282832448fb0281ef53d243c1cd48491"></a><!-- doxytag: member="TimerCounter::TIMER_CTRL" ref="ga282832448fb0281ef53d243c1cd48491" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga282832448fb0281ef53d243c1cd48491">TIMER_CTRL</a>&nbsp;&nbsp;&nbsp;0x43</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The address of the timer control register. <br/></td></tr>
<tr><td colspan="2"><h2>Speaker and Timer2 control and bit meanings</h2></td></tr>
<tr><td colspan="2"><p><a class="anchor" id="amgrp522b10e3c0ddf497a8490aaa34435a31"></a> </p>
<br/><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga51b3a5e3d4811ca063fe25e35560ab40"></a><!-- doxytag: member="TimerCounter::SPEAKER_CTRL" ref="ga51b3a5e3d4811ca063fe25e35560ab40" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga51b3a5e3d4811ca063fe25e35560ab40">SPEAKER_CTRL</a>&nbsp;&nbsp;&nbsp;0x61</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The address of a generic PC register, whose bits 0 and 1 control the timer2 clock and output to the speaker. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga2b2c87cf384febed61fa7cc3a039c692"></a><!-- doxytag: member="TimerCounter::TIMER2_ENABLE" ref="ga2b2c87cf384febed61fa7cc3a039c692" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga2b2c87cf384febed61fa7cc3a039c692">TIMER2_ENABLE</a>&nbsp;&nbsp;&nbsp;(1 &lt;&lt; 0)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Enable Timer 2 clock. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gaddc08f0751fd696a4a21d7e20ce96765"></a><!-- doxytag: member="TimerCounter::SPEAKER_ENABLE" ref="gaddc08f0751fd696a4a21d7e20ce96765" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gaddc08f0751fd696a4a21d7e20ce96765">SPEAKER_ENABLE</a>&nbsp;&nbsp;&nbsp;(1 &lt;&lt; 1)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Enable Timer 2 output to speaker. <br/></td></tr>
<tr><td colspan="2"><h2>Some usefull (and nice) definitions</h2></td></tr>
<tr><td colspan="2"><p><a class="anchor" id="amgrp03a7b5ea01a04131b249a391645b3d29"></a> </p>
<br/><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gae5af43ac16a34537dd1799ef08229aef"></a><!-- doxytag: member="TimerCounter::TIMER_CLK" ref="gae5af43ac16a34537dd1799ef08229aef" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gae5af43ac16a34537dd1799ef08229aef">TIMER_CLK</a>&nbsp;&nbsp;&nbsp;1193181</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The timers input frequency. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gaea17a229fcf743540b24e8acde7b3a8f"></a><!-- doxytag: member="TimerCounter::LCOM_MODE" ref="gaea17a229fcf743540b24e8acde7b3a8f" args="" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gaea17a229fcf743540b24e8acde7b3a8f">LCOM_MODE</a>&nbsp;&nbsp;&nbsp;0x36</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Control byte: LSB followed by MSB, mode 3, binary count. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="gacb14513edfabace28d9ee211c29b3a54"></a><!-- doxytag: member="TimerCounter::LSB" ref="gacb14513edfabace28d9ee211c29b3a54" args="(i)" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#gacb14513edfabace28d9ee211c29b3a54">LSB</a>(i)&nbsp;&nbsp;&nbsp;((i) &amp; 0xFF)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The Least Significative Byte of a Word. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ga100824284a4b3301df9cdd3f49914fde"></a><!-- doxytag: member="TimerCounter::MSB" ref="ga100824284a4b3301df9cdd3f49914fde" args="(i)" -->
#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d7/d38/group___timer_counter.html#ga100824284a4b3301df9cdd3f49914fde">MSB</a>(i)&nbsp;&nbsp;&nbsp;((i) &gt;&gt; 8)</td></tr>
<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The Most Significative Byte of a Word*/. <br/></td></tr>
</table>
<hr/><a name="_details"></a><h2>Descrição detalhada</h2>
<p>Timer-Counter definitions </p>
<hr/><h2>Documentação das funções</h2>
<a class="anchor" id="ga41884d7120e9408d1c5719e2858f6564"></a><!-- doxytag: member="timer.h::mili_sleep" ref="ga41884d7120e9408d1c5719e2858f6564" args="(int mili)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void mili_sleep </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>mili</em></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Wait mili miliseconds, indirectly counting T0 interrupts </p>

<p>Definido na linha <a class="el" href="../../#L42">42</a> do ficheiro <a class="el" href="../../">timer.c</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00043"></a>00043 {
<a name="l00044"></a>00044         <span class="keywordtype">int</span> timeout = msec + mili;
<a name="l00045"></a>00045         <span class="keywordflow">while</span>(msec &lt; timeout) HLT;
<a name="l00046"></a>00046 }
</pre></div></p>

</div>
</div>
<a class="anchor" id="ga0e9d3dc8f167970fe922c56d47d84850"></a><!-- doxytag: member="timer.h::sec_sleep" ref="ga0e9d3dc8f167970fe922c56d47d84850" args="(int secs)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void sec_sleep </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>secs</em></td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>wait secs seconds, indirectly counting T0 interrupts </p>

<p>Definido na linha <a class="el" href="../../#L52">52</a> do ficheiro <a class="el" href="../../">timer.c</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00053"></a>00053 {
<a name="l00054"></a>00054         <a class="code" href="../../d7/d38/group___timer_counter.html#ga41884d7120e9408d1c5719e2858f6564">mili_sleep</a>(secs * 1000);
<a name="l00055"></a>00055 }
</pre></div></p>

</div>
</div>
<a class="anchor" id="ga6617a30ded5d745873f7de678030d10c"></a><!-- doxytag: member="timer.h::timer_init" ref="ga6617a30ded5d745873f7de678030d10c" args="(int timer, int mode)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void timer_init </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>timer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>mode</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Program timer (0,1,2) with mode </p>

<p>Definido na linha <a class="el" href="../../#L5">5</a> do ficheiro <a class="el" href="../../">timer.c</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00006"></a>00006 {
<a name="l00007"></a>00007         outportb(<a class="code" href="../../d7/d38/group___timer_counter.html#ga282832448fb0281ef53d243c1cd48491" title="The address of the timer control register.">TIMER_CTRL</a>, mode | (timer &lt;&lt; 6));
<a name="l00008"></a>00008         
<a name="l00009"></a>00009         <span class="keywordflow">if</span>(timer == 2)
<a name="l00010"></a>00010         {
<a name="l00011"></a>00011                 <span class="keywordtype">char</span> val = inportb(<a class="code" href="../../d7/d38/group___timer_counter.html#ga51b3a5e3d4811ca063fe25e35560ab40" title="The address of a generic PC register, whose bits 0 and 1 control the timer2 clock...">SPEAKER_CTRL</a>);
<a name="l00012"></a>00012                 outportb(<a class="code" href="../../d7/d38/group___timer_counter.html#ga51b3a5e3d4811ca063fe25e35560ab40" title="The address of a generic PC register, whose bits 0 and 1 control the timer2 clock...">SPEAKER_CTRL</a>, val | <a class="code" href="../../d7/d38/group___timer_counter.html#ga2b2c87cf384febed61fa7cc3a039c692" title="Enable Timer 2 clock.">TIMER2_ENABLE</a>);
<a name="l00013"></a>00013         }
<a name="l00014"></a>00014 }
</pre></div></p>

</div>
</div>
<a class="anchor" id="gae17f36dbe5d10ebced7a88cc463a7ea9"></a><!-- doxytag: member="timer.h::timer_load" ref="gae17f36dbe5d10ebced7a88cc463a7ea9" args="(int timer, int value)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void timer_load </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>timer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>value</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Load timer (0,1,2) with value </p>

<p>Definido na linha <a class="el" href="../../#L19">19</a> do ficheiro <a class="el" href="../../">timer.c</a>.</p>

<p><div class="fragment"><pre class="fragment"><a name="l00020"></a>00020 {
<a name="l00021"></a>00021         outportb(0x40 | timer, <a class="code" href="../../d7/d38/group___timer_counter.html#gacb14513edfabace28d9ee211c29b3a54" title="The Least Significative Byte of a Word.">LSB</a>(value));
<a name="l00022"></a>00022         outportb(0x40 | timer, <a class="code" href="../../d7/d38/group___timer_counter.html#ga100824284a4b3301df9cdd3f49914fde" title="The Most Significative Byte of a Word*/.">MSB</a>(value));
<a name="l00023"></a>00023 }
</pre></div></p>

</div>
</div>
</div>
<hr class="footer"/><address style="text-align: right;"><small>Gerado em Tue Jun 1 22:05:39 2010 para FEUP-Defender por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>
